package com.base.dehong.util;

import android.content.Context;
import android.widget.Toast;

/**
 * ToastUtils Toast工具类
 * 2015 12 8 Kenvin 修改   去掉了hideToast（），在show那边做时间判断
 * @author Lee
 */
public class ToastUtils {

	private static Toast toast= null;
	private static long mLastTime = 0;
	private static String mLastStr = "";


	private ToastUtils() {
		throw new AssertionError();
	}

	public static void show(Context context, int resId) {
		show(context, context.getResources().getText(resId), Toast.LENGTH_SHORT);
	}

	public static void show(Context context, CharSequence text) {
		show(context, text, Toast.LENGTH_SHORT);
	}
	public static void showLong(Context context, CharSequence text) {
		show(context, text, Toast.LENGTH_LONG);
	}
	public static void showLong(Context context, int resId) {
		show(context, context.getResources().getText(resId), Toast.LENGTH_LONG);
	}

	/**
	 * 提示单例，新增取消
	 * @param context
	 * @param text
	 * @param duration
	 */
	public static void show(Context context, CharSequence text, int duration) {

		if (toast == null) {
			toast =  Toast.makeText(context, text,
					duration);
		} else {
			if (toast.getDuration() == duration && mLastStr.equals(text)) {
				if (System.currentTimeMillis() - mLastTime > 1200) {
					toast.setText(text);
				}else{
					return;
				}
			}else {
				toast =  Toast.makeText(context, text,
						duration);
				toast.setText(text);
			}
		}
		mLastStr = text.toString();
		mLastTime = System.currentTimeMillis();
		toast.show();
	}
	public static void hideToast() {
//		这里暂时取消掉
//		if (null != toast) {
//			toast.cancel();
//		}
		
	}

}
